package net.jeeshop.web.action.front.appointments;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import net.jeeshop.core.BaseAction;
import net.jeeshop.services.front.appointments.AppointmentsService;
import net.jeeshop.services.front.appointments.bean.Appointments;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author Jerry.hu
 * @summary
 * @Copyright (c) 2016, Lianjia Group All Rights Reserved.
 * @Description To change this template use File | Settings | File Templates.
 * @since 2016-07-14 16:27
 */
public class AppointmentsAction extends BaseAction<Appointments> {

    private static final long serialVersionUID = -7106347072572364304L;

    /**
     * 获取 method for property <tt>appointmentsService</tt>.
     *
     * @return property value of appointmentsService
     */
    public AppointmentsService getAppointmentsService () {
        return appointmentsService;
    }

    /**
     * 设置 method for property <tt>appointmentsService</tt>.
     *
     * @param appointmentsService value to be assigned to property appointmentsService
     */
    public AppointmentsAction setAppointmentsService (AppointmentsService appointmentsService) {
        this.appointmentsService = appointmentsService;
        return this;
    }

    private AppointmentsService appointmentsService;

    @Override
    public void prepare () throws Exception {
        if (this.e == null) {
            this.e = new Appointments();
        }
    }

    @Override
    public Appointments getE () {
        return this.e;
    }

    @Override
    public void insertAfter (Appointments appointments) {
        appointments.clear();
    }

    @Override
    protected void selectListAfter () {

    }


    /**
     * 预约
     * @return
     */
    public String appointments(){
        return "appointments";
    }

    public String addAppointments() throws IOException {
        JSONObject jsonObject = new JSONObject();
        Appointments appointments = getE();
        if(appointments != null){
            appointmentsService.insert(appointments);
            jsonObject.put("status","success");
        }else{
            jsonObject.put("status","fail");
            jsonObject.put("message","预约信息为空");
        }
        getResponse().getWriter().write(jsonObject.toJSONString());
        return null;
    }

}
